#include "meewordsdata.h"
#include <QDebug>

MeeWordsData::MeeWordsData(QObject *parent) : QObject(parent)
{
}

bool MeeWordsData::checkFile(QString _file)
{
    QFileInfo file( _file );

    if( !file.exists() ) {
        return false;
    }

    if( !file.isFile() ) {
        return false;
    }

    if( !file.isReadable() ) {
        return false;
    }

    if( file.size() == 0 ) {
        return false;
    }

    return true;
}

bool MeeWordsData::checkDir(QString _dir)
{
    QDir dir( _dir );

    if( !dir.exists() ) {
        return false;
    }

    if( !dir.isReadable() ) {
        return false;
    }

    return true;
}


QString MeeWordsData::exportWords(QString str, QString path, QString fileName )
{
    QString ret("ok");

    QString strF( path + "/" + fileName );
    QFile f( strF );

    if ( !f.open(QIODevice::WriteOnly | QIODevice::Text) ) {
        ret = "Can't save the file: "+strF;
        return ret;
    }

    QTextStream out(&f);
    out << str;

    f.close();

    return ret;
}

QString MeeWordsData::remEnter(QString srcStr)
{
    return srcStr.replace( QChar('\n'), QChar(' ') );
}
